# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=apr
pkgver=1.7.4
pkgrel=0
pkgdesc="The Apache Portable Runtime"
url="https://apr.apache.org/"
arch="all"
license="Apache-2.0"
depends_dev="util-linux-dev"
makedepends="$depends_dev"
subpackages="$pkgname-dev"
source="https://www.apache.org/dist/apr/apr-$pkgver.tar.bz2
	apr-1.6.2-dont-test-dlclose.patch
	semtimedop-s390x.patch
	"

# secfixes:
#   1.7.1-r0:
#     - CVE-2022-24963
#     - CVE-2022-25147
#     - CVE-2022-28331
#   1.7.0-r2:
#     - CVE-2021-35940

build() {
	case "$CARCH" in
	x86)
		# apr before 1.7.3 implicitly disabled these for i*86
		# now that they're enabled, it seems to fail tests instead
		local atomics=no
		;;
	*)
		local atomics=yes
		;;
	esac
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--datadir=/usr/share \
		--enable-nonportable-atomics=$atomics \
		--with-devrandom=/dev/urandom
	make
}

check() {
	make -j1 check
}

package() {
	make DESTDIR="$pkgdir" install
}

# basicly everything thats not a *.so* file belongs to the -dev package
# we override the pre-defined func.
dev() {
	depends="$pkgname=$pkgver-r$pkgrel $depends_dev"
	mkdir -p "$subpkgdir"
	mv "$pkgdir"/* "$subpkgdir"/
	mkdir -p "$pkgdir"/usr/lib
	mv "$subpkgdir"/usr/lib/*.so* "$pkgdir"/usr/lib/
}

sha512sums="
2342c997765ea2ca96eac158e5fd260232dba68fc41b90a79a7ba9b25c539fc217981867362090e0ebebe632289257c342275e3c5baedb698c474ef8f49a9dcd  apr-1.7.4.tar.bz2
9fb931e45f30fbe68af56849dfca148c09cdf85e300af14fb259cbd43470113288680bdb21189d4cf13f5ce95f8d28666822535e017e64ace5324339ab50cbef  apr-1.6.2-dont-test-dlclose.patch
5d1afa9419d0481e7c3369724e8b4c1e199cbfd5d031bd9d9fc4f46ee0d3819353ff03c3b2c508d5b939f66ef4549953bbf9cdae7ff934002b9a01d824c843e8  semtimedop-s390x.patch
"
